package com.crm.jdy.service.client;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.crm.jdy.common.dto.ClientInfoDto;
import com.crm.jdy.common.pojo.ClientInfo;
import com.crm.jdy.common.mapper.ClientInfoMapper;
//import com.crm.jdy.common.utils.exception.BusinessException;
import com.crm.jdy.service.edu.ClientInfoService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.apache.dubbo.config.annotation.Service;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.util.ObjectUtils;
import java.util.List;

/**   
 * @Description:(客户基本信息管理服务实现)
 *
 * @version: V1.0
 * @author: kong
 * 
 */
@Service(version = "${service.version}")
@Component
public class ClientInfoServiceImpl  extends ServiceImpl<ClientInfoMapper,ClientInfo> implements ClientInfoService  {


    @Autowired
    ClientInfoMapper clientInfoDao;


    @Override
    public PageInfo<ClientInfo> seletePageInfo(ClientInfoDto feedback) {
        PageHelper.startPage( feedback.getCurrentPage(),feedback.getPageSize());
        List<ClientInfo> bookList = clientInfoDao.seleteClientInfo(feedback);
        PageInfo<ClientInfo> pageInfo = new PageInfo<ClientInfo>(bookList);
        return pageInfo;
    }

    @Override
    public boolean updateClientInfo(ClientInfo clientinfo) {
        return clientInfoDao.updateById(clientinfo) > 0;
    }

    @Override
    public boolean addClientInfo(ClientInfo clientinfo) {
        LambdaQueryWrapper<ClientInfo> lambda = new QueryWrapper<ClientInfo>().lambda()
                .eq(ClientInfo::getCName, clientinfo.getCName());
        ClientInfo clientInfo = clientInfoDao.selectOne(lambda);
        if( clientInfo !=null && ObjectUtils.isEmpty(clientInfo)){
            return false;
        }else{
            return clientInfoDao.insert(clientinfo) > 0;
        }

    }

    @Override
    public boolean removeClientInfo(String cid) {
        return clientInfoDao.deleteById(cid) > 0;
    }


}